public class InterruptDemo2 {
    private static volatile boolean isStop = false;

    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            while (true) {
                if (isStop) {
                    System.out.println("线程被中断");
                    break;
                }
                System.out.println("线程执行中...volatile");
            }
        });
        t1.start();

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        new Thread(()->{
            isStop = true;
        }, "t2").start();
    }
}
